package chkui.springcore.example.hybrid.beanmanipulation;

import java.beans.PropertyEditor;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.config.CustomEditorConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;

import chkui.springcore.example.hybrid.beanmanipulation.bean.Address;
import chkui.springcore.example.hybrid.beanmanipulation.bean.DateFormatRegistrar;
import chkui.springcore.example.hybrid.beanmanipulation.propertyEditor.AddressEditor;

@Configurable
@ImportResource("classpath:hybrid/beanmanipulation/config.xml")
public class BeanManipulationConfig {

	@Bean
	CustomEditorConfigurer customEditorConfigurer() {
		// 构建CustomEditorConfigurer
		CustomEditorConfigurer configurer = new CustomEditorConfigurer();
		
		Map<Class<?>, Class<? extends PropertyEditor>> customEditors = new HashMap<>();
		
		// 添加AddressEditor和Address的绑定
		customEditors.put(Address.class, AddressEditor.class);
		
		// 添加绑定列表
		configurer.setCustomEditors(customEditors);
		
		// 通过PropertyEditorRegistrar注册PropertyEditor
		configurer.setPropertyEditorRegistrars(new PropertyEditorRegistrar[] { new DateFormatRegistrar() });
		return configurer;
	}
}
